<template>
  <com-card>
    <div slot="com_header">
      <el-row>
        <el-form :model="orderList" :inline="true">
          <el-form-item label="订单号">
            <el-input
              type="text"
              v-model="orderList.orderNo"
              placeholder="订单号"
            ></el-input>
          </el-form-item>
          <el-form-item label="收货人">
            <el-input
              type="text"
              v-model="orderList.consignee"
              placeholder="收货人"
            ></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input
              type="text"
              v-model="orderList.phone"
              placeholder="手机号"
            ></el-input>
          </el-form-item>
          <el-form-item label="订单状态">
            <el-select name="" id="" v-model="orderList.orderState">
              <el-option value="已受理">已受理</el-option>
              <el-option value="派送中">派送中</el-option>
              <el-option value="已完成">已完成</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择时间">
            <el-date-picker
              v-model="datetime"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="primary" @click="query"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
      </el-row>
    </div>

    <div slot="com_con">
      <el-table :data="tableList" border style="width: 100%" v-loading="loa">
        <el-table-column fixed prop="orderNo" label="订单号" width="90">
        </el-table-column>
        <el-table-column label="下单时间" width="120">
          <template slot-scope="{ row }">
            <!-- <div>{{row.orderTime | timeMF_s}}</div> -->
            <div>{{ row.orderTime | timeMF }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机号" width="120">
        </el-table-column>
        <el-table-column prop="consignee" label="收货人" width="120">
        </el-table-column>
        <el-table-column prop="deliverAddress" label="送货地址" width="120">
        </el-table-column>
        <el-table-column label="送达时间" width="240">
          <template slot-scope="{ row }">
            <div>{{ row.deliveryTime | timeMF }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="用户备注" width="120">
        </el-table-column>
        <el-table-column prop="orderAmount" label="订单金额" width="120">
        </el-table-column>
        <el-table-column prop="orderState" label="订单状态" width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="{ row }">
            <el-button
              type="text"
              size="small"
              @click="gopath('/order/detail', row.id)"
              >查看</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="gopath('/order/update', row.id)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.orderList.currentPage"
        :page-sizes="[5, 6, 7, 8]"
        :page-size="this.orderList.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </com-card>
</template>

<script>
import ComCard from "../../components/card";
import { api_query } from "../../api/order.js";
export default {
  components: {
    ComCard,
  },
  mounted() {
    this.query();
  },
  data() {
    return {
      loa: true,
      flag: true,
      tableList: [],
      datetime: [],
      total: 0,
      orderList: {
        currentPage: 1,
        pageSize: 5,
        orderNo: "",
        consignee: "",
        phone: "",
        orderState: "",
        date: "",
      },
    };
  },
  methods: {
    //分页
    handleSizeChange(val) {
      this.orderList.pageSize = val;
      this.query();
    },
    handleCurrentChange(val) {
      this.orderList.currentPage = val;
      this.query();
      console.log(`当前页: ${val}`);
    },

    async query() {
      if (this.flag) {
        this.flag=false
        this.loa=true
        this.orderList.date = JSON.stringify(this.datetime);
        let rst = await api_query(this.orderList);
        let { total, data } = rst;
        this.tableList = data;
        this.total = total;
        this.loa=false
        this.flag=ture

        console.log(rst);
        console.log(this.orderList.date);
        console.log(this.datetime);
      }
    },

    //订单详情、修改
    gopath(path, id) {
      this.$router.push({ path, query: { id } });
    },
  },
};
</script>

<style lang="less" scoped>
</style>